package com.kuang.boot.config;

//import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.View;
//import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Locale;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
//    如果你想定义一些制定化的功能，只要写这个组件然后将它交给boot，其会自动装配
//    扩展springmvc dispatchservlet


//    viewresolver实现了视图解析器的接口类，可以看做就是一个疏通解析器
//    @Bean
//    public ViewResolver myViewResolver(){
//     return new MyViewResolver();
//    }

//        自定义一个自己的视图解析器
//    public static class MyViewResolver implements ViewResolver{
//    @Override
//         public View resolveViewName(String s, Locale locale) throws Exception {
//             return null;
//    }
//}

    @Bean
    public LocaleResolver myLocaleResolver(){
        return new MyLocalResolver();
    }


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }

//    添加拦截器注入

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).
                addPathPatterns("/**").
                excludePathPatterns("/index.html","/user/login","/","/css/*","/js/**","/img/**");
    }
}
